<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <body>

        <ui:composition template="/resources/template/template.xhtml">


            <ui:define name="content">

                <p:panel header="Change Membership" style="width: 100%" >
                    <table style="width: 100%" class="alignTop">
                        <tr>
                            <td style="width: 10%" >
                                <h:form>
                                    <p:panelGrid columns="1" >
                                        <p:commandButton value="List All Members" ajax="false"
                                                         action="#{patientController.listAllMembers()}" ></p:commandButton>
                                        <p:commandButton value="List All Persons" ajax="false"
                                                         action="#{patientController.listAllPatients()}" ></p:commandButton>
                                    </p:panelGrid>
                                </h:form>
                            </td>
                            <td style="width: 90%" >
                                <h:form>
                                    <p:panelGrid columns="3" >
                                        <p:outputLabel value="New Membership Scheme" ></p:outputLabel>
                                        <p:selectOneMenu id="membershipScheme" value="#{patientController.membershipScheme}" >
                                            <f:selectItems value="#{membershipSchemeController.items}" var="m" itemLabel="#{m.name}" itemValue="#{m}"/>
                                        </p:selectOneMenu>
                                        <p:commandButton value="Update Membership for Selected" ajax="false"
                                                         action="#{patientController.changeMembershipOfSelectedPersons()}" ></p:commandButton>

                                    </p:panelGrid>

                                    <p:dataTable value="#{patientController.items}" var="p" rowIndexVar="n"
                                                 selection="#{patientController.selectedItems}" rowKey="#{p.id}"
                                                 rows="10"
                                                 paginator="true"
                                                 paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                                 rowsPerPageTemplate="5,10,15"
                                                 >
                                        <p:column selectionMode="multiple" width="10" ></p:column>
                                        <p:column headerText="Name" sortBy="#{p.person.nameWithTitle}" filterBy="#{p.person.nameWithTitle}">
                                            <p:outputLabel value="#{p.person.nameWithTitle}" ></p:outputLabel>
                                        </p:column>
                                        <p:column headerText="Age" sortBy="#{p.age}" filterBy="#{p.age}">
                                            <p:outputLabel value="#{p.age}" ></p:outputLabel>
                                        </p:column>
                                        <p:column headerText="Sex" sortBy="#{p.person.sex}" filterBy="#{p.person.sex}">
                                            <p:outputLabel value="#{p.person.sex}" ></p:outputLabel>
                                        </p:column>
                                        <p:column headerText="Phone" sortBy="#{p.person.phone}" filterBy="#{p.person.phone}">
                                            <p:outputLabel value="#{p.person.phone}" ></p:outputLabel>
                                        </p:column>
                                        <p:column headerText="Address" sortBy="#{p.person.address}" filterBy="#{p.person.address}">
                                            <p:outputLabel value="#{p.person.address}" ></p:outputLabel>
                                        </p:column>
                                        <p:column headerText="Mebership" sortBy="#{p.person.membershipScheme.name}" filterBy="#{p.person.membershipScheme.name}">
                                            <p:outputLabel value="#{p.person.membershipScheme.name}" ></p:outputLabel>
                                        </p:column>


                                    </p:dataTable>


                                </h:form>
                            </td>
                        </tr>
                    </table>
                </p:panel>
            </ui:define>



        </ui:composition>

    </body>
</html>
